package com.sgb.kjwl.view.ui.fragment.packers;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentPackerChangeSecondItemBinding;
import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.sgb.kjwl.model.entity.FindPackersEntity;
import com.sgb.kjwl.model.entity.FindPeopleEntity;
import com.sgb.kjwl.model.entity.PopularWorkersEntity;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.packers.EmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.FindPeopleDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.LaborServiceAndEmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.pick.TenderDetailsActivity3;
import com.sgb.kjwl.view.ui.adapter.packers.FindPackersAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.FindPeopleAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.LaborServiceAndEmploymentAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PackerHallBidingAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PackersEmploymentAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PopularWorkersAdapter;
import com.sgb.kjwl.view.ui.adapter.pick.PickHallBidingAdapter;
import com.sgb.kjwl.viewmodel.packers.PackerChangeSecondViewModel;
import com.sgb.link.router.PathTeam;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import com.swgk.core.recyclerview.decoration.RecyclerCustomDecoration;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : younghow
 * @date : 2021/8/18 15:06
 * description:工队首页下半部的fragment 这个界面包含了七个列表，所以在参数和方法数略显繁杂，其实这是不正确的(违背了单一原则)
 */
public class PackersChangeListItemFragment extends AppLazyFragment {

    private FragmentPackerChangeSecondItemBinding mBinding;
    private PackerChangeSecondViewModel mViewModel;
    /**
     * 下面这几个是判断页面是否正在执行加载更多的操作的判断依据，作为后面设置adapter的一个依据
     * isLoadMore 判断劳务用工
     * isLoadMoreTeamBuild 判断施工工队
     * isLoadMoreTeamClassGroup 判断班组工队
     * isLoadMoreWorker 判断工人
     * isLoadMoreTemporaryEmployment 判断临时用工
     * isLoadMoreFindBuild 判断首页-找工程
     * isLoadMoreFindBuild
     */
    private boolean isLoadMore;
    private boolean isLoadMoreTeamBuild;
    private boolean isLoadMoreTeamClassGroup;
    private boolean isLoadMoreWorker;
    private boolean isLoadMoreTemporaryEmployment;
    private boolean isLoadMoreFindBuild;
    private boolean isLoadMorePopular;

    /**
     * 下面这几个是判断页数的依据
     * page 判断劳务用工
     * pageTeamBuild 判断施工工队
     * pageTeamClassGroup 判断班组工队
     * pageTeamWorker 判断工人
     * pageTemporaryEmployment 临时用工
     * pageFindBuild 首页-找工程的页数
     * pagePopular 判断人气工队
     */
    private int page = 1;
    private int pageTeamBuild = 1;
    private int pageTeamClassGroup = 1;
    private int pageWorker = 1;
    private int pageTemporaryEmployment  = 1;
    private int pageFindBuild = 1;
    private int pagePopular = 1;

    /**
     * 下面的这几个是这些列表的adapter
     * mAdapter 劳务用工
     * findPackersClassGroupAdapter 班组工队
     * findPeopleAdapter 找工人
     * findPackersBuildAdapter 施工工队
     * adapter 临时用工
     * mFindBuildAdapter 首页-找工程
     * popularWorkersAdapter 人气工队
     */
    private LaborServiceAndEmploymentAdapter mAdapter;
    private FindPackersAdapter findPackersClassGroupAdapter;
    private FindPackersAdapter findPackersBuildAdapter;
    private FindPeopleAdapter findPeopleAdapter;
    private PackersEmploymentAdapter adapter;
    private PackerHallBidingAdapter mFindBuildAdapter;
    private PopularWorkersAdapter popularWorkersAdapter;

    private int secondType = 1;
    private int thirdType = 3;

    /**
     * 首页选择的地址的code，这里也可能会改变
     */
    private String mAreaCode = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.AREA_CODE,"");

    /**
     * 类型
     */
    private int type;

    public static PackersChangeListItemFragment newInstance(int type) {
        PackersChangeListItemFragment fragment = new PackersChangeListItemFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type",type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_packer_change_second_item, container, false);
        return mBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PackerChangeSecondViewModel.class);
        if (getArguments() != null) {
            type = getArguments().getInt("type");
        }
    }

    private void initData() {
        if (type == 1 || type == 2){
            if (type == 1){
                setAdapter(1);
                loadData(1,false);
            }else {
                setAdapter(3);
                loadData(3,false);
            }
        }else {
            setAdapter(type);
            loadData(type,false);
        }
    }

    @Override
    public void initView() {
        mBinding.xrvPackerChangeSecondPublishList.setLayoutManager(new LinearLayoutManager(getContext()));
        mBinding.xrvPackerChangeSecondPublishList.setLoadingMoreEnabled(true);
        mBinding.xrvPackerChangeSecondPublishList.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                if (type == 1 || type == 2){
                    if (type == 1){
                        setAdapter(secondType);
                        loadData(secondType,false);
                    }else {
                        setAdapter(thirdType);
                        loadData(thirdType,false);
                    }
                }else {
                    loadData(type,false);
                }
            }

            @Override
            public void onLoadMore() {
                if (type == 1 || type == 2){
                    if (type == 1){
                        setAdapter(secondType);
                        loadData(secondType,true);
                    }else {
                        setAdapter(thirdType);
                        loadData(thirdType,true);
                    }
                }else {
                    loadData(type,true);
                }
            }
        });

        if (type == 1 || type == 2){
            mBinding.tlPackerChangeSecondTitle.setVisibility(View.VISIBLE);
            if (type == 1){
                String[] title = {"临时用工","劳务用工"};
                mBinding.tlPackerChangeSecondTitle.addTab(mBinding.tlPackerChangeSecondTitle.newTab().setText(title[0]));
                mBinding.tlPackerChangeSecondTitle.addTab(mBinding.tlPackerChangeSecondTitle.newTab().setText(title[1]));
            }else if (type == 2){
                String[] title = {"班组工队","施工队","人气工队"};
                mBinding.tlPackerChangeSecondTitle.addTab(mBinding.tlPackerChangeSecondTitle.newTab().setText(title[0]));
                mBinding.tlPackerChangeSecondTitle.addTab(mBinding.tlPackerChangeSecondTitle.newTab().setText(title[1]));
                mBinding.tlPackerChangeSecondTitle.addTab(mBinding.tlPackerChangeSecondTitle.newTab().setText(title[2]));
            }
        }else {
            mBinding.tlPackerChangeSecondTitle.setVisibility(View.GONE);
        }

        mBinding.tlPackerChangeSecondTitle.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int selectType = tab.getPosition();
                mBinding.tlPackerChangeSecondTitle.postDelayed(() -> mBinding.tlPackerChangeSecondTitle.getTabAt(selectType).select(),100);
                if (type == 1){
                    secondType = selectType + 1;
                    setAdapter(secondType);
                    loadData(secondType,false);
                }else if (type == 2){
                    thirdType = selectType + 3;
                    setAdapter(thirdType);
                    loadData(thirdType,false);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        initAdapter();
        initLiveData();
    }

    @Override
    protected void onLazyLoad() {
        initData();
    }

    public void onRefresh() {
        mAreaCode = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.AREA_CODE,"");
        if (type == 1 || type == 2){
            mBinding.tlPackerChangeSecondTitle.postDelayed(() -> mBinding.tlPackerChangeSecondTitle.getTabAt(0).select(),100);
            secondType = 1;
            thirdType = 3;
            if (type == 1){
                setAdapter(secondType);
                loadData(secondType,false);
            }else {
                setAdapter(thirdType);
                loadData(thirdType,false);
            }
        }else {
            loadData(type,false);
        }
    }

    /**
     * 这里是请求网络需要实现的方法，以type来判断我们需要请求哪一个接口
     * @param type 0 找工人 3 找工程 其他的因为是二级的数据 所以我们这里不做讨论
     * @param isLoadMore 这里和我们的全局变量一样，是判断是否加载更多的一个依据
     */
    private void loadData(int type, boolean isLoadMore){
        if (mViewModel == null){
            mViewModel = new ViewModelProvider(this).get(PackerChangeSecondViewModel.class);
        }

        mAreaCode = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.AREA_CODE,"");

        switch (type) {
            case 0:
                loadWorkerData(isLoadMore);
                break;
            case 1:
                loadTemporaryEmploymentData(isLoadMore);
                break;
            case 2:
                loadLaborData(isLoadMore);
                break;
            case 3:
            case 4:
                loadTeamData(type, isLoadMore);
                break;
            case 5:
                loadPopularData(isLoadMore);
                break;
            case 6:
                loadTenderApplyingList(isLoadMore);
                break;
            default:
                break;
        }
    }

    /**
     * 加载劳务用工的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadLaborData(boolean isLoadMore){
        this.isLoadMore = isLoadMore;
        if (isLoadMore){
            page++;
        }else {
            page = 1;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("limit",20);
        map.put("page",page);
        map.put("provinceNo", mAreaCode);
        mViewModel.signUpTerm(map);
    }

    /**
     * 加载班组工队或者施工工队的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     * @param type 这里传入这个参数还是为了去请求对应的参数
     */
    private void loadTeamData(int type,boolean isLoadMore){
        Map<String,Object> map = new HashMap<>(4);
        if (type == 4){
            this.isLoadMoreTeamBuild = isLoadMore;
            if (isLoadMore){
                pageTeamBuild++;
            }else {
                pageTeamBuild = 1;
            }
            map.put("page",pageTeamBuild);
            map.put("teamType",0);
        }else if (type == 3){
            this.isLoadMoreTeamClassGroup = isLoadMore;
            if (isLoadMore){
                pageTeamClassGroup++;
            }else {
                pageTeamClassGroup = 1;
            }
            map.put("page",pageTeamClassGroup);
            map.put("teamType",1);
        }
        map.put("limit",20);
        map.put("provinceNo", mAreaCode);
        mViewModel.getTeamList(map);
    }

    /**
     * 加载首页-找工程的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadTenderApplyingList(boolean isLoadMore){
        this.isLoadMoreFindBuild = isLoadMore;
        if (isLoadMore){
            pageFindBuild++;
        }else {
            pageFindBuild = 1;
        }

        Map<String,Object> map = new HashMap<>();
        map.put("areacode", mAreaCode);
        map.put("limit",20);
        map.put("page",pageFindBuild);
        map.put("type", "4");
        map.put("sortMethod", "1");
        mViewModel.getTenderApplyingList(map);
    }

    /**
     * 加载找工人的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadWorkerData(boolean isLoadMore){
        this.isLoadMoreWorker = isLoadMore;
        if (isLoadMore){
            pageWorker++;
        }else {
            pageWorker = 1;
        }
        Map<String,Object> map = new HashMap<>(3);
        map.put("limit",20);
        map.put("page", pageWorker);
        map.put("provinceNo", mAreaCode);
        mViewModel.getWorkerList(map);
    }

    /**
     * 加载人气工队的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadPopularData(boolean isLoadMore){
        this.isLoadMorePopular = isLoadMore;
        if (isLoadMore){
            pagePopular++;
        }else {
            pagePopular = 1;
        }
        Map<String,Object> map = new HashMap<>(3);
        map.put("limit",20);
        map.put("page", pagePopular);
        map.put("provinceNo", mAreaCode);
        mViewModel.getPopularList(map);
    }

    /**
     * 加载临时用工的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadTemporaryEmploymentData(boolean isLoadMore){
        this.isLoadMoreTemporaryEmployment = isLoadMore;
        if (isLoadMore){
            pageTemporaryEmployment++;
        }else {
            pageTemporaryEmployment = 1;
        }
        Map<String,Object> map = new HashMap<>(3);
        map.put("limit",20);
        map.put("page", pageTemporaryEmployment);
        map.put("provinceNo", mAreaCode);
        mViewModel.getTemporaryEmploymentList(map);
    }

    /**
     * 刚刚我们提到，这整个界面有7个列表，这里我们为了省时间就写在了一个界面上(其实这是不正确的，这违背了单一原则),所以我们在这里去设置对应的adapter
     * @param type 0 找工人  3 找工程 其他的因为是二级的adapter 所以我们这里不做操作
     */
    private void setAdapter(int type){
        switch (type){
            case 0:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(findPeopleAdapter);
                break;
            case 1:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(adapter);
                break;
            case 2:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(mAdapter);
                break;
            case 3:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(findPackersClassGroupAdapter);
                break;
            case 4:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(findPackersBuildAdapter);
                break;
            case 5:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(popularWorkersAdapter);
                break;
            case 6:
                mBinding.xrvPackerChangeSecondPublishList.setAdapter(mFindBuildAdapter);
                break;
            default:
                break;
        }
    }

    private void initAdapter() {
        setLaborAdapter();
        setBuildAdapter();
        setClassGroupAdapter();
        setWorkerAdapter();
        setTemporaryEmploymentAdapter();
        setFindBuildAdapter();
        setPopularAdapter();
    }

    /**
     * 初始化劳务用工的adapter,包含点击之后需要跳转的地方
     */
    private void setLaborAdapter(){
        mAdapter = new LaborServiceAndEmploymentAdapter(getContext(), null);
        mAdapter.setOnItemClick(new AdapterOnItemClick<LabourServiceAndEmploymentEntity>() {
            @Override
            public void onItemClick(LabourServiceAndEmploymentEntity labourServiceAndEmploymentEntity, int position) {
                ActivityJump.jumpToActivityForResult(getActivity(), LaborServiceAndEmploymentDetailActivity.class,0, Pair.create("no",labourServiceAndEmploymentEntity.getNo()),Pair.create("workNo",labourServiceAndEmploymentEntity.getWorkNo()),Pair.create("workName",labourServiceAndEmploymentEntity.getCategoryName()), Pair.create("isFocus",labourServiceAndEmploymentEntity.getIsFocus()),Pair.create("isApply",labourServiceAndEmploymentEntity.isApply()),Pair.create("mMomentNo",labourServiceAndEmploymentEntity.getUserNo()),Pair.create("workNameForList",labourServiceAndEmploymentEntity.getWorkName()),Pair.create("employmentType",labourServiceAndEmploymentEntity.getEmploymentType()),Pair.create("imId",labourServiceAndEmploymentEntity.getImId()));
            }
        });
    }

    /**
     * 初始化找工程的adapter,包含点击之后需要跳转的地方
     */
    private void setFindBuildAdapter(){
        mFindBuildAdapter = new PackerHallBidingAdapter(getActivity(), null);

        mFindBuildAdapter.setOnItemClick(new AdapterOnItemClick<TenderListEntity>() {
            @Override
            public void onItemClick(TenderListEntity tenderListEntity, int position) {
                TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId(), 0);
            }
        });
        mFindBuildAdapter.onIChildClick(tenderListEntity -> TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId(), 0));

    }

    /**
     * 初始化人气工队的adapter,包含点击之后需要跳转的地方
     */
    private void setPopularAdapter(){
        popularWorkersAdapter = new PopularWorkersAdapter(getActivity(), null, Glide.with(this));

        popularWorkersAdapter.setOnItemClick(new AdapterOnItemClick<PopularWorkersEntity>() {
            @Override
            public void onItemClick(PopularWorkersEntity popularWorkersEntity, int position) {
                mViewModel.teamParticulars(popularWorkersEntity.getNo());
            }
        });
    }

    /**
     * 初始化班组工队的adapter,包含点击之后需要跳转的地方
     */
    private void setClassGroupAdapter(){
        findPackersClassGroupAdapter = new FindPackersAdapter(getActivity(), null, Glide.with(this),false);
        findPackersClassGroupAdapter.setOnItemClick(new AdapterOnItemClick<FindPackersEntity>() {
            @Override
            public void onItemClick(FindPackersEntity findPackersEntity, int position) {
                mViewModel.getH5Url(findPackersEntity.getNo());
            }
        });
    }

    /**
     * 初始化施工工队的adapter,包含点击之后需要跳转的地方
     */
    private void setBuildAdapter(){
        findPackersBuildAdapter = new FindPackersAdapter(getActivity(), null, Glide.with(this),true);
        findPackersBuildAdapter.setOnItemClick(new AdapterOnItemClick<FindPackersEntity>() {
            @Override
            public void onItemClick(FindPackersEntity findPackersEntity, int position) {
                mViewModel.getH5Url(findPackersEntity.getNo());
            }
        });
    }

    /**
     * 初始化工人关注的adapter,包含点击之后需要跳转的地方
     */
    private void setWorkerAdapter(){
        findPeopleAdapter = new FindPeopleAdapter(getContext(), null, Glide.with(this));
        findPeopleAdapter.setOnItemClick(new AdapterOnItemClick<FindPeopleEntity>() {
            @Override
            public void onItemClick(FindPeopleEntity findPeopleEntity, int position) {
                FindPeopleDetailActivity.start(getContext(), findPeopleEntity.getNo());
            }
        });
    }

    /**
     * 初始化临时用工关注的adapter,包含点击之后需要跳转的地方
     */
    private void setTemporaryEmploymentAdapter(){
        adapter = new PackersEmploymentAdapter(getContext(), null, 0);
        adapter.setOnItemClick(new AdapterOnItemClick<EmploymentEntity>() {
            @Override
            public void onItemClick(EmploymentEntity employmentEntity, int position) {
                EmploymentDetailActivity.startForResult(getActivity(), employmentEntity.getNo(), employmentEntity.getProjectName(),employmentEntity.isIsApply(),0);
            }
        });
    }

    private void initLiveData() {
        setLaborListLiveData();
        setStatusLiveData();
        setTeamListLiveData();
        setH5LiveData();
        setWorkerListLiveData();
        setTemporaryEmploymentListLiveData();
        setFindBuildListLiveData();
        setPopularLiveData();
        setTenderH5LiveData();
    }

    /**
     * 这里是更新网络请求状态的liveData,一共包括三个状态，加载，成功或失败
     */
    private void setStatusLiveData(){
        mViewModel.loadingLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.showProgressDialog(getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false));
        mViewModel.successLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());
        mViewModel.errorLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());
    }

    /**
     * 劳务用工数据返回，需要设置adapter
     */
    private void setLaborListLiveData(){
        mViewModel.mFollowSuccessLiveData.observe(getViewLifecycleOwner(), labourServiceAndEmploymentEntities -> {
            if (isLoadMore) {
                if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                    mAdapter.addDatas(labourServiceAndEmploymentEntities);
                }
                if (labourServiceAndEmploymentEntities != null) {
                    mBinding.xrvPackerChangeSecondPublishList.setNoMore(labourServiceAndEmploymentEntities.size() < 15);
                }
                mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    mAdapter.setDatas(labourServiceAndEmploymentEntities);
                    mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                    if (labourServiceAndEmploymentEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                    }
                } else {
                    mAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 施工工队和班组工队数据返回，需要设置adapter
     */
    private void setTeamListLiveData(){
        mViewModel.mFollowTeamLiveData.observe(getViewLifecycleOwner(), findPackersEntities -> {
            if (thirdType == 4){
                if (isLoadMoreTeamBuild) {
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        findPackersBuildAdapter.addDatas(findPackersEntities);
                    }
                    if (findPackersEntities != null) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(findPackersEntities.size() < 15);
                    }
                    mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
                } else {
                    mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        mBinding.emptyView.setVisibility(View.GONE);
                        findPackersBuildAdapter.setDatas(findPackersEntities);
                        mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                        if (findPackersEntities.size() < NumberConstant.NUMBER_TEN) {
                            mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                        }
                    } else {
                        findPackersBuildAdapter.clearDatas();
                        mBinding.emptyView.setVisibility(View.VISIBLE);
                    }
                }
            }else if (thirdType == 3){
                if (isLoadMoreTeamClassGroup) {
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        findPackersClassGroupAdapter.addDatas(findPackersEntities);
                    }
                    if (findPackersEntities != null) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(findPackersEntities.size() < 15);
                    }
                    mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
                } else {
                    mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        mBinding.emptyView.setVisibility(View.GONE);
                        findPackersClassGroupAdapter.setDatas(findPackersEntities);
                        mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                        if (findPackersEntities.size() < NumberConstant.NUMBER_TEN) {
                            mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                        }
                    } else {
                        findPackersClassGroupAdapter.clearDatas();
                        mBinding.emptyView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
    }

    /**
     * 工人数据返回，需要设置adapter
     */
    private void setWorkerListLiveData(){
        mViewModel.mFollowWorkerLiveData.observe(getViewLifecycleOwner(), findPeopleEntities -> {
            if (isLoadMoreWorker) {
                if (findPeopleEntities != null && findPeopleEntities.size() > 0) {
                    findPeopleAdapter.addDatas(findPeopleEntities);
                }
                if (findPeopleEntities != null) {
                    mBinding.xrvPackerChangeSecondPublishList.setNoMore(findPeopleEntities.size() < 15);
                }
                mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                if (findPeopleEntities != null && findPeopleEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    findPeopleAdapter.setDatas(findPeopleEntities);
                    mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                    mBinding.xrvPackerChangeSecondPublishList.setLoadingMoreEnabled(true);
                    if (findPeopleEntities.size() < NumberConstant.NUMBER_FIFTEEN) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                    }
                } else {
                    findPeopleAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 临时用工关注数据返回，需要设置adapter
     */
    private void setTemporaryEmploymentListLiveData(){
        mViewModel.mFollowTemporaryEmploymentLiveData.observe(getViewLifecycleOwner(), employmentEntities -> {
            if (isLoadMoreTemporaryEmployment) {
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    adapter.addDatas(employmentEntities);
                }
                if (employmentEntities != null) {
                    mBinding.xrvPackerChangeSecondPublishList.setNoMore(employmentEntities.size() < 10);
                }
                mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    adapter.setDatas(employmentEntities);
                    mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                    if (employmentEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                    }
                } else {
                    adapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 去到工队的详情页，h5页面
     */
    private void setH5LiveData(){
        mViewModel.mUrlLiveData.observe(getViewLifecycleOwner(), s -> {
            String[] split = s.split("----");
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.TeamDetailActivity, Pair.create("no",split[1]),Pair.create("url",split[0]));
        });
    }

    /**
     * 去到招标的详情页，h5页面
     */
    private void setTenderH5LiveData(){
        mViewModel.mUrlTenderLiveData.observe(getViewLifecycleOwner(), s -> {
            String[] split = s.split("----");
            WebViewX5HostActivity.start(getActivity(), split[1], split[0]);
        });
    }

    private void setFindBuildListLiveData(){
        mViewModel.mSuccessFindBuildLiveData.observe(getViewLifecycleOwner(), tenderListEntities -> {
            if (isLoadMoreFindBuild) {
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    mFindBuildAdapter.addDatas(tenderListEntities);
                }
                if (tenderListEntities != null) {
                    mBinding.xrvPackerChangeSecondPublishList.setNoMore(tenderListEntities.size() < 10);
                }
                mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    mFindBuildAdapter.setDatas(tenderListEntities);
                    mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                    if (tenderListEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                    }
                } else {
                    mFindBuildAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private void setPopularLiveData(){
        mViewModel.mSuccessPopularLiveData.observe(getViewLifecycleOwner(), tenderListEntities -> {
            if (isLoadMorePopular) {
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    popularWorkersAdapter.addDatas(tenderListEntities);
                }
                if (tenderListEntities != null) {
                    mBinding.xrvPackerChangeSecondPublishList.setNoMore(tenderListEntities.size() < 10);
                }
                mBinding.xrvPackerChangeSecondPublishList.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvPackerChangeSecondPublishList.refreshComplete();
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    popularWorkersAdapter.setDatas(tenderListEntities);
                    mBinding.xrvPackerChangeSecondPublishList.smoothScrollToPosition(0);
                    if (tenderListEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPackerChangeSecondPublishList.setNoMore(true);
                    }
                } else {
                    popularWorkersAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        mAreaCode = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.AREA_CODE,"");

        if (NumberConstant.sIsBackForTeam == 1){
            onRefresh();
            NumberConstant.sIsBackForTeam = 0;
        }
    }
}
